<template>
	<view style="position: relative">
		<view>
			<input placeholder="请输入昵称" v-model="nickName" maxlength="15"/>
		</view>
		<view>
			<button class="sure" @click="edit()">确定</button>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import http from '@/common/request.js';
import { getCommonShareInfo } from '@/common/utils.js';
export default {
	onShareAppMessage() {
		return getCommonShareInfo()
	},
	data() {
		return {
			nickName: ''
		}
	},
	mounted() {
		// this.nickName = this.userInfo.nickName
	},
	computed: {
		...mapState({ userInfo: state => state.userInfo })
	},
	methods: {
		edit() {
			http('/api/cusUserInfo', {data: {userId: this.userInfo.userId, nickName: this.nickName}, method: 'PUT'}).then(
				result => {
					if(result.code == '200') {
						this.nickName ? this.$store.commit("UPDATE_USERINFO", {nickName: this.nickName}) : this.userInfo.nickName
						uni.navigateBack({
							delta: 1,
							animationType: 'pop-out',
							animationDuration: 200
						});
					}
				},
				result => {
					this.showLoading = false
					uni.showToast({
						title: result.msg,
						icon: 'none'
					})
				}
			)
		}
	}
}
</script>

<style lang="less" scoped>
	input {
		height: 90rpx;
		line-height: 90rpx;
		padding: 0 28rpx;
		background: #fff;
		font-size: 30rpx;
		color: #66645D;
	}
	.sure {
		height: 82rpx;
		background: #FACC6B;
		line-height: 82rpx;
		color: #66645D;
		font-size: 30rpx;
		position: fixed;
		left: 28rpx;
		bottom: 36rpx;
		width: 93%;
	}
</style>
